import 'package:flutter/material.dart';
import 'package:huajianshe_app/base/BaseState.dart';
import 'package:huajianshe_app/common/load_image.dart';
import 'package:huajianshe_app/common/res.dart';
import 'package:huajianshe_app/pages/user_info/model/UserModel.dart';
import 'package:huajianshe_app/widget/AvatarWidget.dart';
import 'package:huajianshe_app/widget/RoundedCornerWidget.dart';

class MemberItem extends StatefulWidget {

  final FriendInfo? friendInfo;

  const MemberItem(this.friendInfo, {Key? key, }) : super(key: key);

  @override
  State<StatefulWidget> createState() {
    return MemberItemState();
  }
}

class MemberItemState extends BaseState<MemberItem> {
  @override
  Widget build(BuildContext context) {
    return InkWell(onTap: () => userDetail(), child: Padding(padding: EdgeInsets.symmetric(vertical: 10),
      child: Row(mainAxisSize: MainAxisSize.max, crossAxisAlignment: CrossAxisAlignment.center, children: [
        if (widget.friendInfo?.showRadio == true)
          GestureDetector(onTap: () => { check() }, child: Padding(padding: EdgeInsets.only(top: 8, bottom: 8, right: 10),
              child: widget.friendInfo?.checked == true ? LoadImage('ic_radio_checked_22') : LoadImage('ic_radio_unchecked_22'))),
        if (widget.friendInfo?.showRadio == true) W(7),
        RoundedCornerWidget(width: 40, height: 40, radius: 20, padding: EdgeInsets.all(0),  child:
        AvatarWidget(widget.friendInfo?.userInfo?.avatar ?? '', 40, 0, 0), backgroundColor: Colors.white, borderWidth: 0,
        ),
        W(8),
        Column(mainAxisSize: MainAxisSize.max,
            crossAxisAlignment: CrossAxisAlignment.start, children: [
              Row(mainAxisSize: MainAxisSize.max, children: [
                Text(widget.friendInfo?.userInfo?.nickname ?? '', style: TS(15, C.gray333)),
              ]),
              H(3),
              Text('${widget.friendInfo?.userInfo?.companyName}${widget.friendInfo?.userInfo?.positionName}', style: TS(12, C.gray666))
            ]),
        Spacer(),
        LoadImage('ic_gray_right_arrow')
      ]),
    ));
  }

  check() {
    print('checked: ${widget.friendInfo?.checked}');
    if (widget.friendInfo?.checked == null) {
      widget.friendInfo?.checked = true;
    } else {
      widget.friendInfo?.checked = !(widget.friendInfo!.checked!);
    }
    setState(() => null);
  }

  userDetail() {

  }
}